﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace WpfApp2
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void ShowDream_Click(object sender, RoutedEventArgs e)
        {
            StringBuilder dream = new StringBuilder();
            foreach (UIElement myPanelChild in myPanel.Children)
            {
                if(myPanelChild is CheckBox)
                {
                    CheckBox cbx = (CheckBox)myPanelChild;
                    if (cbx.IsChecked == true)
                    {
                        dream.Append(cbx.Content + ",");
                    }
                }
            }
            if (dream.Length > 0)
            {
                dream = dream.Remove(dream.Length - 1, 1);
                MessageBox.Show(dream.ToString());
            }
        }

        private void OnChecked(object sender, RoutedEventArgs e)
        {
            int total = 0;
            foreach (UIElement myPanelChild in myPanel.Children)
            {
                if (myPanelChild is CheckBox)
                {
                    CheckBox cbx = (CheckBox)myPanelChild;
                    if (cbx.IsChecked == true)
                    {
                        if (++total > 3)
                        {
                            (sender as CheckBox).IsChecked = false;
                            MessageBox.Show("最多可选三个");
                            break;
                        }
                    }
                }
            }
            
        }
    }
}
